//
//  YMOperateVideoListCell.m
//  YMMedical
//
//  Created by y s on 2023/7/20.
//

#import "YMOperateVideoListCell.h"
#import "YMMedicalTools.h"

@interface YMOperateVideoListCell ()

@property (nonatomic, strong) UIImageView *imgvPic;
@property (nonatomic, strong) UILabel *lblTitle;
@property (nonatomic, strong) UILabel *lblDate;

@end

@implementation YMOperateVideoListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI methods
- (void)setUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = STheme.D9;
    [self.contentView addSubview:self.imgvPic];
    [self.contentView addSubview:self.lblTitle];
    [self.contentView addSubview:self.lblDate];
    
    [self.imgvPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.top.mas_equalTo([SFitUtil fit:15]);
        make.size.mas_equalTo([SFitUtil fitSize:122 height:69]);
    }];
    [self.lblTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgvPic);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.left.equalTo(self.imgvPic.mas_right).offset([SFitUtil fit:15]);
    }];
    [self.lblDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imgvPic);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.left.equalTo(self.imgvPic.mas_right).offset([SFitUtil fit:15]);
        make.top.greaterThanOrEqualTo(self.lblTitle.mas_bottom).offset([SFitUtil fit:5]);
    }];
}


#pragma mark - public methods
+ (CGFloat)getCellHeight{
    return [SFitUtil fit:30+69];
}
- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    self.lblTitle.text = [SDataUtil stringOf:dict[@"ufwm5h3hjvu3f0bq"] valid:@""];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *date = [formatter dateFromString:[SDataUtil stringOf:_dict[@"created_at"] valid:@""]];
    formatter.dateFormat = @"yyyy-MM-dd";
    
    self.lblDate.text = [NSString stringWithFormat:@"%@ 上传",[formatter stringFromDate:date]];
    NSArray *arrVideo = [SDataUtil arrayOf:dict[@"b2fpmprchh9sgoaa"]];
    if (arrVideo.count > 0){
        NSDictionary *dictTemp = [SDataUtil dictOf:arrVideo.firstObject];
        self.imgvPic.image = [YMMedicalTools firstFrameWithVideoURL:[SDataUtil stringOf:dictTemp[@"url"] valid:@""] size:CGSizeMake(SCREEN_WIDTH*2, [SFitUtil fit:210]*2)];
    }else{
        self.imgvPic.image = [UIImage imageWithColor:STheme.D4];
    }
}

#pragma mark - Event Action

#pragma mark - setter and getter
- (UIImageView *)imgvPic{
    if (_imgvPic == nil){
        _imgvPic = [[UIImageView alloc] init];
        _imgvPic.backgroundColor = STheme.D4;
        _imgvPic.layer.cornerRadius = [SFitUtil fit:4];
        _imgvPic.contentMode = UIViewContentModeScaleAspectFill;
        _imgvPic.clipsToBounds = YES;
    }
    return _imgvPic;
}
- (UILabel *)lblTitle{
    if (_lblTitle == nil){
        _lblTitle = [SThemeUtil boldLabel:@"" color:0x3D3D3D fontSize:14];
        _lblTitle.numberOfLines = 2;
    }
    return _lblTitle;
}
- (UILabel *)lblDate{
    if (_lblDate == nil){
        _lblDate = [SThemeUtil boldLabel:@"" color:STheme.H_D3 fontSize:12];
    }
    return _lblDate;
}

@end
